//=============================================================================
// WeaponHammer.
//=============================================================================
class WeaponMarkusHammer extends TNMWeapon;

var travel int EffectMode;
var string EffectNames[10];
var Pawn JetPacker;

function Timer()
{
 if ((JetPacker == None) || (JetPacker.IsInState('Dying')))
  return;
 else if ((JetPacker != None) && (!JetPacker.IsInState('Dying')))
 {
  JetPacker.SetPhysics(PHYS_Falling);
  JetPacker.Velocity.Z += 6500;
  JetPacker.TakeDamage(10, Pawn(Owner), JetPacker.Location, vect(0,0,0), 'Exploded');
  SetTimer(0.5, False);
 }
}

function SpawnWormholeEffects(Vector Wormhole1, Vector Wormhole2)
{
 local sphereeffect WH1, WH2;

 WH1 = Spawn(class'SphereEffect',,, WormHole1);
 WH2 = Spawn(class'SphereEffect',,, WormHole2); 

}

function MoveVictim(Pawn Victim)
{
	local actor a;
	local int numactors, i, n;
	local actor LevelActors[256];
	
		foreach allactors (class'Actor', a)
			if ((A.IsA('Decoration')) && (!A.Region.Zone.IsA('SkyZoneInfo')))
                        //make us pop up somewhere completely random OTHER than the sky box...
			// only use these actors for a starting point
			{
				numactors++;
				if (NumActors < 256) // dont go outside our array
					LevelActors[NumActors] = A; // add the actor to the list
				else
					break;
			}	
			n = Rand(NumActors); // pick a random actor from the list we just made
			TeleportVictim(Victim, LevelActors[n]); // teleport the victim using that actor
}

function TeleportVictim(Pawn Subject, Actor DestinationActor)
{
	local vector OrigLocation, Destination, DestNormal, EndTrace, Correction, RVect;
	local int i;	
	local actor hit;

	if (Subject == None)
		return;

	OrigLocation = Subject.Location;

	for (i=0;i<5;i++)
	{
		RVect = VRand();
		RVect.Z = 0;
		EndTrace = DestinationActor.Location + RVect*65536; // some vector very far away in a random direction ferom the DestinationActor
		hit = DestinationActor.Trace(Destination, DestNormal, EndTrace, DestinationActor.Location, True); // find where this line hits a wall
	/*	if (Destination.Z - OrigLocation.Z > MaxZ)
		{
			Correction = Destination;
			Correction.Z = OrigLocation.Z + MaxZ;
			hit = DestinationActor.Trace(Destination, DestNormal, EndTrace, OrigLocation, True);*/ // okay stuff 3D
		Destination += DestNormal*Subject.CollisionHeight; // we dont want them half in a wall/floor
		if(Subject.SetLocation(Destination)) // make sure they got there
		{
			return;
		}
	}
        SpawnWormholeEffects(OrigLocation, Destination);
	BroadcastMessage("|P2Failed to move victim.");		
}

function CycleAmmo()
{
 EffectMode++;
if (EffectMode > 9)
 EffectMode = 0;

Pawn(Owner).ClientMessage(EffectNames[EffectMode]);

 //handle the REALY dangerous stuff from a longer range...
 if ((EffectMode == 5) || (EffectMode == 8))
 {
  MaxRange = 1024;
  AccurateRange = 1024;
 }

 //and fix it if its not...
 else
 {
  MaxRange = 80;
  AccurateRange = 80;
 }
}

function SpawnEffects(Vector HitLocation, Vector HitNormal, Actor Other, float Damage)
{
local pawn OHGODTHEPOKETS;
local DiarrhiaFragment chunk;
local TNMLam ClusterBombs;
local int i;
local int j;
local float size;

else if (EffectMode == 2) //implosive diarrhia
 Super.SpawnEffects(HitLocation, HitNormal, Other, Damage * -2);
else //anything else
 Super.SpawnEffects(HitLocation, HitNormal, Other, Damage);

 if (Other.IsA('Pawn'))
 {
  OHGODTHEPOKETS = Pawn(Other);

                //and don't forget to make them shit themselves no matter what mode we're on...
		size = (OHGODTHEPOKETS.CollisionRadius + OHGODTHEPOKETS.CollisionHeight) / 2;
		if (size > 10.0)
		{
			for (i=0; i<size/4.0; i++)
			{
				loc.X = (1-2*FRand()) * OHGODTHEPOKETS.CollisionRadius;
				loc.Y = (1-2*FRand()) * OHGODTHEPOKETS.CollisionRadius;
				loc.Z = (1-2*FRand()) * OHGODTHEPOKETS.CollisionHeight;
				loc += OHGODTHEPOKETS.Location;
				chunk = spawn(class'DiarrhiaFragment', None,, loc);
				if (chunk != None)
				{
					chunk.DrawScale = size / 25;
					chunk.SetCollisionSize(chunk.CollisionRadius / chunk.DrawScale, chunk.CollisionHeight / chunk.DrawScale);
					chunk.bFixedRotationDir = True;
					chunk.RotationRate = OHGODTHEPOKETS.RotRand(False);
				}
			}
                       if (EffectMode == 8) //clusterbombs OH NOES!
			for (j=0; j<size/4.0; j++)
			{
				loc.X = (1-2*FRand()) * OHGODTHEPOKETS.CollisionRadius;
				loc.Y = (1-2*FRand()) * OHGODTHEPOKETS.CollisionRadius;
				loc.Z = (1-2*FRand()) * OHGODTHEPOKETS.CollisionHeight;
				loc += OHGODTHEPOKETS.Location;
				ClusterBombs = spawn(class'TNMLam', None,, loc);
				if (ClusterBombs != None)
				{
					ClusterBombs.DrawScale = size / 25;
					ClusterBombs.SetCollisionSize(ClusterBombs.CollisionRadius / ClusterBombs.DrawScale, ClusterBombs.CollisionHeight / ClusterBombs.DrawScale);
					ClusterBombs.bFixedRotationDir = True;
					ClusterBombs.RotationRate = OHGODTHEPOKETS.RotRand(False);
				}
			}
		}
 if (EffectMode == 6) //wormholes... gotta love em.
  MoveVictim(OHGODTHEPOKETS);
 if (EffectMode == 5) //blackholes too.
  Spawn(Class'BlackHole',,,HitLocation); //i assume the user knows that a black hole is dangerous...
 }
}

simulated function ProcessTraceHit(Actor Other, Vector HitLocation, Vector HitNormal, Vector X, Vector Y, Vector Z)
{
	local thrownprojectile nade;
	local tripproj trip;

	nade=ThrownProjectile(other);
	if(nade!=None)
	{
		trip=TripProj(nade);
		if(trip!=None)
		{
			trip.Disarm();
			return;
		}
		if(!nade.bDisabled)
			nade.Frob(None,None);
		return;
	}

        if ((Pawn(Other) != None) && (EffectMode == 7))
        {
         JetPacker = Pawn(Other);
         SetTimer(0.1, False);
        }

	super.ProcessTraceHit(Other,HitLocation,HitNormal,X,Y,Z);
}

function name WeaponDamageType()
{
      if (EffectMode == 3)
       return ('flamed'); //molten diarrhia

      else if (EffectMode == 4)
       return ('poisoned'); //acidic diarrhia
      
      else if (EffectMode == 5)
       return ('Exploded'); //blackhole

      else if (EffectMode == 9)
       return ('EMP'); //nuclear blitzarria

      else if (EffectMode == 0)
       return ('shot'); //normal diarrhia

      else
       return ('fat'); //anything else
}

defaultproperties
{
     hitfleshsound=Sound'DeusExSounds.Weapons.CrowbarHitFlesh'
     hitwoodsound=Sound'DeusExSounds.Weapons.CrowbarHitSoft'
     hitmetalsound=Sound'DeusExSounds.Weapons.CrowbarHitHard'
     bGetsBloody=True
     LowAmmoWaterMark=0
     GoverningSkill=Class'DeusEx.SkillWeaponLowTech'
     NoiseLevel=0.050000
     EnemyEffective=ENMEFF_Organic
     Concealability=CONC_All
     reloadTime=0.000000
     HitDamage=13
     maxRange=80
     AccurateRange=80
     BaseAccuracy=1.000000
     bHasMuzzleFlash=False
     bHandToHand=True
     bFallbackWeapon=True
     bEmitWeaponDrawn=False
     mpHitDamage=20
     mpBaseAccuracy=1.000000
     mpAccurateRange=96
     mpMaxRange=96
     AmmoName=Class'DeusEx.AmmoNone'
     ReloadCount=0
     bInstantHit=True
     FireOffset=(X=-5.000000,Y=8.000000,Z=14.000000)
     shakemag=20.000000
     FireSound=Sound'DeusExSounds.Weapons.CrowbarFire'
     SelectSound=Sound'DeusExSounds.Weapons.CrowbarSelect'
     InventoryGroup=255
     ItemName="Markus's Hammer of Lulzitude"
     PlayerViewOffset=(X=5.000000,Y=-8.000000,Z=-14.000000)
     PlayerViewMesh=LodMesh'TNMItems.WeaponHammer'
     PlayerViewScale=0.400000
     PickupViewMesh=LodMesh'TNMItems.HammerPickup'
     PickupViewScale=0.600000
     ThirdPersonMesh=LodMesh'TNMItems.Hammer3rd'
     ThirdPersonScale=0.350000
     Icon=Texture'TNMItems.Skins.BeltIconTNMHammer'
     largeIcon=Texture'TNMItems.Skins.LargeIconTNMHammer'
     largeIconWidth=49
     largeIconHeight=45
     Description="It's Hammer Time! WARNING: Sideaffects may include backfirearea."
     beltDescription="OH SHI-"
     Mesh=LodMesh'TNMItems.HammerPickup'
     CollisionRadius=12.650000
     CollisionHeight=1.200000
     EffectNames(0)="Sideaffect set to diarrhia."
     EffectNames(1)="Sideaffect set to explosive diarrhia."
     EffectNames(2)="Sideaffect set to implosive diarrhia."
     EffectNames(3)="Sideaffect set to molten diarrhia."
     EffectNames(4)="Sideaffect set to acidic diarrhia."
     EffectNames(5)="Sideaffect set to Black Hole-arrhia."
     EffectNames(6)="Sideaffect set to Worm Hole-arrhia."
     EffectNames(7)="Sideaffect set to Jetpack-arrhia."
     EffectNames(8)="Sideaffect set to Cluster Bomb-arrhia."
     EffectNames(9)="Sideaffect set to Nuclear Blitz-arrhia."
}
